cmake_minimum_required(VERSION 2.8)

project(RabbitIm)

if(POLICY CMP0020)
    cmake_policy(SET CMP0020 NEW)
endif()

set(QT_COMPONENTS Multimedia)

#QZXing库
OPTION(OPTION_RABBITIM_USE_QZXING "Use QZXing library" ON)
if(OPTION_RABBITIM_USE_QZXING)
    FIND_PACKAGE(QZXing)
    if(QZXing_FOUND)
        LIST(APPEND RABBITIM_LIBS QZXing)
        list(APPEND RABBITIM_DEFINES RABBITIM_USE_QZXING)
        INSTALL_TARGETS(TARGETS QZXing)
    endif()
endif()
message("Found QZXing:${QZXing_FOUND}")

include(Files.cmake)

#资源
LIST(APPEND RABBITIM_RCC_FILES
    ${CMAKE_SOURCE_DIR}/Resource/Resource.qrc
    )

LIST(APPEND RABBITIM_RCC_FILES
    Emoji/Emojis/emojione.qrc
    Emoji/Emojis/smileys.qrc
    )

#IF(ANDROID)
#    INSTALL(DIRECTORY Emoji/Emojis
#        DESTINATION assets
#        COMPONENT Runtime)
#ELSE()
#    INSTALL(DIRECTORY Emoji/Emojis
#        DESTINATION .
#        COMPONENT Runtime)
#ENDIF()

set(INCLUDE_DIRS
    $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
    $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/common>
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Widgets/FrmCustom>
    $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/Plugin>
    )

IF(MSVC)
    add_compile_options("/wd4819")  #删除不是GBK字符的警告  
    list(APPEND RABBITIM_DEFINES WINDOWS)
ELSEIF(MINGW)
    list(APPEND RABBITIM_DEFINES WINDOWS)
ELSEIF(ANDROID)
    list(APPEND RABBITIM_DEFINES MOBILE)
    ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/android/QtAndroidUtils/android/QtAndroidUtilsModule/jni
        ${CMAKE_BINARY_DIR}/QtAndroidUtilsModule)
    LIST(APPEND RABBITIM_LIBS QtAndroidUtilsModule)
    list(APPEND QT_COMPONENTS AndroidExtras)
ELSE(LINUX OR UNIX)
    list(APPEND RABBITIM_DEFINES UNIX)
ENDIF()

find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${QT_COMPONENTS})
if(Qt${QT_VERSION_MAJOR}_FOUND)
    FOREACH(_COMPONENT ${QT_COMPONENTS})
        list(APPEND QT_LIBRARIES Qt${QT_VERSION_MAJOR}::${_COMPONENT})
    ENDFOREACH()
endif()
LIST(APPEND RABBITIM_LIBS RabbitCommon)
foreach(l ${_QT_COMPONENTS})
    set(RabbitIm_QT_COMPONENTS "${RabbitIm_QT_COMPONENTS} ${l}")
endforeach()
ADD_TARGET(NAME ${PROJECT_NAME}
    SOURCE_FILES ${RABBITIM_SOURCES} ${HEADER_FILES} ${RABBITIM_UIS} ${RABBITIM_RCC_FILES}
    LIBS ${RABBITIM_LIBS} ${QT_LIBRARIES}
    DEFINITIONS RABBITCOMMON ${RABBITIM_DEFINES}
    PRIVATE_DEFINITIONS DLL_EXPORT
    INCLUDE_DIRS ${INCLUDE_DIRS}
    INSTALL_HEADER_FILES ${INSTALL_HEADER_FILES}
    INSTALL_EXPORT_NAME ${PROJECT_NAME}Targets
    )
